home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / urandom < prev    next >
Encoding:
Text File  |  2013-01-10  |  1.9 KB  |  80 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          urandom
  4. # Required-Start:    $local_fs
  5. # Required-Stop:     $local_fs
  6. # Default-Start:
  7. # Default-Stop:
  8. # Short-Description: Save and restore random seed between restarts.
  9. # Description:       This script saves the random seed between restarts.
  10. #                    It is called from the boot, halt and reboot scripts.
  11. ### END INIT INFO
  12.  
  13. [ -c /dev/urandom ] || exit 0
  14.  
  15. PATH=/sbin:/bin
  16. SAVEDFILE=/var/lib/urandom/random-seed
  17. POOLSIZE=512
  18. [ -f /proc/sys/kernel/random/poolsize ] && POOLSIZE="$(cat /proc/sys/kernel/random/poolsize)"
  19. . /lib/init/vars.sh
  20.  
  21. . /lib/lsb/init-functions
  22.  
  23. do_status () {
  24.     if [ -f $SAVEDFILE ] ; then
  25.         return 0
  26.     else
  27.         return 4
  28.     fi
  29. }
  30.  
  31. case "$1" in
  32.   start|"")
  33.     [ "$VERBOSE" = no ] || log_action_begin_msg "Initializing random number generator"
  34.     # Load and then save $POOLSIZE bytes,
  35.     # which is the size of the entropy pool
  36.     if [ -f "$SAVEDFILE" ]
  37.     then
  38.         # Handle locally increased pool size
  39.         set -- $(LC_ALL=C ls -l "$SAVEDFILE")
  40.         SAVEDSIZE="$5"
  41.         if [ "$SAVEDSIZE" -gt "$POOLSIZE" ]
  42.         then
  43.             [ -w /proc/sys/kernel/random/poolsize ] && echo $POOLSIZE > /proc/sys/kernel/random/poolsize
  44.             POOLSIZE=$SAVEDSIZE
  45.         fi
  46.         cat "$SAVEDFILE" >/dev/urandom
  47.     fi
  48.     rm -f $SAVEDFILE
  49.     # Hm, why is the saved pool re-created at boot? [pere 2009-09-03]
  50.     umask 077
  51.     dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
  52.     ES=$?
  53.     umask 022
  54.     [ "$VERBOSE" = no ] || log_action_end_msg $ES
  55.     ;;
  56.   stop)
  57.     # Carry a random seed from shut-down to start-up;
  58.     # see documentation in linux/drivers/char/random.c
  59.     [ "$VERBOSE" = no ] || log_action_begin_msg "Saving random seed"
  60.     umask 077
  61.     dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
  62.     ES=$?
  63.     [ "$VERBOSE" = no ] || log_action_end_msg $ES
  64.     ;;
  65.   status)
  66.     do_status
  67.     exit $?
  68.     ;;
  69.   restart|reload|force-reload)
  70.     echo "Error: argument '$1' not supported" >&2
  71.     exit 3
  72.     ;;
  73.   *)
  74.     echo "Usage: urandom start|stop" >&2
  75.     exit 3
  76.     ;;
  77. esac
  78.  
  79. :
  80.